package com.ruoyi.patrol.controller;

import java.util.List;

import com.ruoyi.patrol.domain.PtCheckType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PtCheckRecord;
import com.ruoyi.patrol.service.IPtCheckRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专项检查Controller
 *
 * @author Du
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/patrol/check")
public class PtCheckRecordController extends BaseController {
    @Autowired
    private IPtCheckRecordService ptCheckRecordService;

    /**
     * 查询专项检查列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(PtCheckRecord ptCheckRecord) {
        startPage();
        List<PtCheckRecord> list = ptCheckRecordService.selectPtCheckRecordList(ptCheckRecord);
        return getDataTable(list);
    }
    /**
     * 查询专项检查类型列表
     */
//    @GetMapping("/app/list")
//    public TableDataInfo appList(PtCheckRecord ptCheckRecord) {
//        startPage();
//        List<PtCheckType> list = ptCheckRecordService.selectPtCheckTypeAndSchoolList(ptCheckRecord);
//        return getDataTable(list);
//    }
    /**
     * 导出专项检查列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:check:export')")
    @Log(title = "专项检查", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PtCheckRecord ptCheckRecord) {
        List<PtCheckRecord> list = ptCheckRecordService.selectPtCheckRecordList(ptCheckRecord);
        ExcelUtil<PtCheckRecord> util = new ExcelUtil<PtCheckRecord>(PtCheckRecord.class);
        return util.exportExcel(list, "check");
    }

    /**
     * 获取专项检查详细信息
     */
    @PreAuthorize("@ss.hasPermi('patrol:check:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(ptCheckRecordService.selectPtCheckRecordById(id));
    }

    /**
     * 新增专项检查
     */
    @PreAuthorize("@ss.hasPermi('patrol:check:add')")
    @Log(title = "专项检查", businessType = BusinessType.INSERT)
    @PostMapping

    public AjaxResult add(@RequestBody PtCheckRecord ptCheckRecord) {
        return toAjax(ptCheckRecordService.insertPtCheckRecord(ptCheckRecord));
    }

    /**
     * 修改专项检查
     */
    @PreAuthorize("@ss.hasPermi('patrol:check:edit')")
    @Log(title = "专项检查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtCheckRecord ptCheckRecord) {
        return toAjax(ptCheckRecordService.updatePtCheckRecord(ptCheckRecord));
    }

    /**
     * 删除专项检查
     */
    @PreAuthorize("@ss.hasPermi('patrol:check:remove')")
    @Log(title = "专项检查", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ptCheckRecordService.deletePtCheckRecordByIds(ids));
    }
}
